﻿<%@ Page Title="" Language="C#" MasterPageFile="~/uc/Shop.Master" AutoEventWireup="true" CodeBehind="message.aspx.cs" Inherits="ncp.Web.Shop.message" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" runat="server">
<title>站内留言_中国农业信息化服务商</title>
<script src="/js/paging.js" type="text/javascript"></script>

    <script src="/Plugin/asyncbox/asyncbox.v1.5.beta.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="rightContent" runat="server">
<div class="bh-dian-right-h-yy">
        <h3>站内留言</h3>
</div>
<div class="bh-dian-con-yy">
        <table height="254">
          <tr>
            <td width="107" height="21" align="center"><img src="../image/xiao-xx-yy.jpg" /> 您的姓名：</td>
            <td width="254"><input name="" id="userName" type="text" class="bh-input-long" maxlength="50"/></td>
            <td width="308"></td>
          </tr>
          <tr>
            <td height="79" align="center"><img src="../image/xiao-xx-yy.jpg" /> 留言内容：</td>
            <td><textarea class="msgContent" id="msgContent"></textarea></td>
            <td valign="bottom">(您的留言内容将对我们帮助很大)</td>
          </tr>
          <tr>
            <td height="34" align="center"><img src="../image/xiao-xx-yy.jpg" /> 您的电话：</td>
            <td><input name="" type="text" id="userPhone" class="bh-input-long" maxlength="20"/></td>
            <td>（例如：50189：210210）</td>
          </tr>
          <tr>
            <td height="39" align="center"> <img src="../image/xiao-xx-yy.jpg" /> 您的邮件：</td>
            <td><input name="" type="text" id="userEmail" class="bh-input-long" maxlength="50"/></td>
            <td>（例如：abc@163.com）</td>
          </tr>
          <tr>
            <td height="39" align="center"> 验证码：</td>
            <td>
                <input type="text" class="required bh-input-small" id="tbcode"/>
                <img id="checkImage" src="/work/VerificationCode.aspx" width="93" height="25"  alt="验证码"　title="验证码" />
                看不清 <span class="bh-blue bh-udline" style="cursor:pointer;" onclick="onfresh()" id="check" >换一张</span>
			</td>
            <td></td>
          </tr>
          <tr>
            <td colspan="3" align="center"><input name="" onclick="onSave()" type="button" class="bh-menben2-yy"  />&nbsp;<input name="" value="" type="reset"  class="bh-menben3-yy" /></td>
          </tr>
        </table>
        
        <!----> 
      </div>
      <script type="text/javascript">
      $(function() {
          $("#userName,#msgContent,#userPhone,#userEmail,#tbcode").keypress(function(e) {
              var key = window.event ? e.keyCode : e.which;
              if (key.toString() == "13") {
                  onSave();
                  return false;
              }
          });
      });
          function onSave() {
              if (getByteLen($("#userName").val()) ==0) {
                  alert("姓名不能为空!");
                  $("#userName").focus();
                  return;
              }
            if (getByteLen($("#userName").val())>50) {
                alert("姓名长度不能超过50个字符!");
                $("#userName").focus();
                return;
            }
            if (getByteLen($("#msgContent").val()) ==0) {
                alert("留言内容不能为空!");
                $("#msgContent").focus();
                return;
            } 
            if (getByteLen($("#msgContent").val())>200) {
                alert("留言内容长度不能超过200个字符!");
                $("#msgContent").focus();
                return;
            }
            if (getByteLen($("#userPhone").val()) ==0) {
                alert("电话号码不能为空!");
                $("#userPhone").focus();
                return;
            }
            if (getByteLen($("#userPhone").val()) > 20) {
                alert("电话号码过长!");
                $("#userPhone").focus();
                return;
            }
            if (getByteLen($("#userEmail").val()) > 50) {
                alert("邮件地址过长!");
                $("#userEmail").focus();
                return;
            }
            if (!isEmail($("#userEmail").val())) {
                alert("邮箱地址不正确!");
                $("#userEmail").focus();
                return;
            }
            if (isEmpty("tbcode")) {
                alert("验证码不能为空!");
                $("#tbcode").focus();
                return;
            }
            var response = ncp.Web.Shop.message.VerificationCode($("#tbcode").val());
              if (response.value != null) {
                  var jsonOBJ = eval(response.value)[0];
                  if (!jsonOBJ.isreload) {
                      alert("验证码错误");
                      onfresh();
                      return;
                  }
              }
              if (isLogin()) {
                  onSendMsg();
              } else {
              asyncbox.open({
                  title: '请登录后留言',
                  id: 'login',
                  width: "330px",
                  height: "160px",
                  url: '/Shop/loginbox.aspx',
                  ctrlbar: {
                      close: false
                  },
                  buttons: asyncbox.btn.OKCANCEL,
                  callback: function(buttonResult, contentWindow, returnValue) {
                      if (buttonResult == 'ok') {
                          var username = asyncbox.framer('login_content').document.getElementById('username').value;
                          var pwd = asyncbox.framer('login_content').document.getElementById('password').value;
                          var boo = login(username, pwd);
                          return boo;
                      }
                      return true;
                  }
              });
              }
          }

          function login(username, pwd) {
              if ($.trim(username) == "") {
                  alert("用户名不能为空！");
                  return false;
              }
              if ($.trim(pwd) == "") {
                  alert("密码不能为空！");
                  return false;
              }
              var response = ncp.Web.Shop.message.UserLogin(username, pwd);
              if (response.value != "") {
                  var jsonOBJ = eval(response.value)[0];
                  if (jsonOBJ.isreload) {
                      onSendMsg();
                      userStatues();
                      return true;
                  } else {
                  alert(jsonOBJ.msg);
                      return false;
                  }
              }
              return false;
          }

          function onSendMsg() {
              var ele = new Object();
              ele.Message_Name = $("#userName").val();
              ele.Message_Tel = $("#userPhone").val();
              ele.Message_Email = $("#userEmail").val();
              ele.Message_Note = $("#msgContent").val();
              var response = ncp.Web.Shop.message.OnSaveMessage($.objectToJson(ele), shopId);
              if (response.value != "") {
                  var jsonOBJ = eval(response.value)[0];
                  alert(jsonOBJ.msg);
                  if (jsonOBJ.isreload) {
                      emptyData();
                  } else {
                      if (jsonOBJ.msg == "0") {
                          location.href = "/Shop/error.aspx";
                      }
                  }
              }
          }

          //判断用户是否已经登录
          function isLogin() {
              var response = ncp.Web.Shop.message.IsLogin();
              return response.value;
          }
        function emptyData() {
            $("#userName,#userPhone,#userEmail,#msgContent,#tbcode").val("");
            onfresh();
        }
        function onfresh() {
            var rand = Math.random() * 1000;
            $("#checkImage").attr("src", "/work/VerificationCode.aspx?" + rand);
        }
      </script>
</asp:Content>
